home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kdeprint / driver.h next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  10.7 KB  |  384 lines

  1. /*
  2.  *  This file is part of the KDE libraries
  3.  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
  4.  *
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License version 2 as published by the Free Software Foundation.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public License
  16.  *  along with this library; see the file COPYING.LIB.  If not, write to
  17.  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  *  Boston, MA 02110-1301, USA.
  19.  **/
  20.  
  21. #ifndef DRIVER_H
  22. #define DRIVER_H
  23.  
  24. #if !defined( _KDEPRINT_COMPILE ) && defined( __GNUC__ )
  25. #warning internal header, do not use except if you are a KDEPrint developer
  26. #endif
  27.  
  28. #include <qstring.h>
  29. #include <qptrlist.h>
  30. #include <qdict.h>
  31. #include <qmap.h>
  32. #include <qrect.h>
  33. #include <qsize.h>
  34.  
  35. #include <kdelibs_export.h>
  36.  
  37. class DriverItem;
  38. class QListView;
  39.  
  40. /***********************
  41.  * Forward definitions *
  42.  ***********************/
  43.  
  44. class DrBase;
  45. class DrMain;
  46. class DrGroup;
  47. class DrConstraint;
  48. class DrPageSize;
  49.  
  50. /*************************************
  51.  * Base class for all driver objects *
  52.  *************************************/
  53.  
  54. /**
  55.  * @internal
  56.  * This class is internal to KDEPrint and is not intended to be
  57.  * used outside it. Please do not make use of this header, except
  58.  * if you're a KDEPrint developer. The API might change in the
  59.  * future and binary compatibility might be broken.
  60.  */
  61. class KDEPRINT_EXPORT DrBase
  62. {
  63. public:
  64.     enum Type { Base = 0, Main, ChoiceGroup, Group, String, Integer, Float, List, Boolean };
  65.  
  66.     DrBase();
  67.     virtual ~DrBase();
  68.  
  69.     Type type() const                     { return m_type; }
  70.     bool isOption() const                     { return (m_type >= DrBase::String); }
  71.  
  72.     const QString& get(const QString& key) const         { return m_map[key]; }
  73.     void set(const QString& key, const QString& val)    { m_map[key] = val; }
  74.     bool has(const QString& key) const             { return m_map.contains(key); }
  75.     const QString& name() const                { return m_name; }
  76.     void setName(const QString& s)                { m_name = s; }
  77.     bool conflict() const                     { return m_conflict; }
  78.     void setConflict(bool on)                { m_conflict = on; }
  79.  
  80.     virtual QString valueText();
  81.     virtual QString prettyText();
  82.     virtual void setValueText(const QString&);
  83.     virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
  84.     virtual void setOptions(const QMap<QString,QString>& opts);
  85.     virtual void getOptions(QMap<QString,QString>& opts, bool incldef = false);
  86.     virtual DrBase* clone();
  87.  
  88. protected:
  89.     QMap<QString,QString>    m_map;
  90.     QString            m_name;        // used as a search key, better to have defined directly
  91.     Type            m_type;
  92.     bool            m_conflict;
  93. };
  94.  
  95. /**********************
  96.  * Option group class *
  97.  **********************/
  98.  
  99. /**
  100.  * @internal
  101.  * This class is internal to KDEPrint and is not intended to be
  102.  * used outside it. Please do not make use of this header, except
  103.  * if you're a KDEPrint developer. The API might change in the
  104.  * future and binary compatibility might be broken.
  105.  */
  106. class KDEPRINT_EXPORT DrGroup : public DrBase
  107. {
  108. public:
  109.     DrGroup();
  110.     ~DrGroup();
  111.  
  112.     void addOption(DrBase *opt);
  113.     void addGroup(DrGroup *grp);
  114.     void addObject(DrBase *optgrp);
  115.     void clearConflict();
  116.     void removeOption(const QString& name);
  117.     void removeGroup(DrGroup *grp);
  118.     bool isEmpty();
  119.  
  120.     virtual DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
  121.     DrBase* findOption(const QString& name, DrGroup **parentGroup = 0);
  122.     DrGroup* findGroup(DrGroup *grp, DrGroup **parentGroup = 0);
  123.     void setOptions(const QMap<QString,QString>& opts);
  124.     void getOptions(QMap<QString,QString>& opts, bool incldef = false);
  125.     DrBase* clone();
  126.  
  127.     const QPtrList<DrGroup>& groups()    { return m_subgroups; }
  128.     const QPtrList<DrBase>& options()    { return m_listoptions; }
  129.  
  130.     static QString groupForOption( const QString& optname );
  131.  
  132. protected:
  133.     void createTree(DriverItem *parent);
  134.     void flattenGroup(QMap<QString, DrBase*>&, int&);
  135.  
  136. protected:
  137.     QPtrList<DrGroup>    m_subgroups;
  138.     QDict<DrBase>    m_options;
  139.     QPtrList<DrBase>    m_listoptions;    // keep track of order of appearance
  140. };
  141.  
  142. /*********************
  143.  * Main driver class *
  144.  *********************/
  145.  
  146. /**
  147.  * @internal
  148.  * This class is internal to KDEPrint and is not intended to be
  149.  * used outside it. Please do not make use of this header, except
  150.  * if you're a KDEPrint developer. The API might change in the
  151.  * future and binary compatibility might be broken.
  152.  */
  153. class KDEPRINT_EXPORT DrMain : public DrGroup
  154. {
  155. public:
  156.     DrMain();
  157.     ~DrMain();
  158.  
  159.     DriverItem* createTreeView(QListView *parent);
  160.     void addConstraint(DrConstraint *c)        { m_constraints.append(c); }
  161.     int checkConstraints();
  162.     DrPageSize* findPageSize(const QString& name)    { return m_pagesizes.find(name); }
  163.     void addPageSize(DrPageSize *sz);
  164.     void removeOptionGlobally(const QString& name);
  165.     void removeGroupGlobally(DrGroup *grp);
  166.     QMap<QString, DrBase*> flatten();
  167.     DrMain* cloneDriver();
  168.  
  169. protected:
  170.     QPtrList<DrConstraint>    m_constraints;
  171.     QDict<DrPageSize>    m_pagesizes;
  172. };
  173.  
  174. /**********************************************************
  175.  * Choice group class: a choice that involve a sub-option *
  176.  **********************************************************/
  177.  
  178. /**
  179.  * @internal
  180.  * This class is internal to KDEPrint and is not intended to be
  181.  * used outside it. Please do not make use of this header, except
  182.  * if you're a KDEPrint developer. The API might change in the
  183.  * future and binary compatibility might be broken.
  184.  */
  185. class DrChoiceGroup : public DrGroup
  186. {
  187. public:
  188.     DrChoiceGroup();
  189.     ~DrChoiceGroup();
  190.  
  191.     DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
  192. };
  193.  
  194. /***********************
  195.  * String option class *
  196.  ***********************/
  197.  
  198. /**
  199.  * @internal
  200.  * This class is internal to KDEPrint and is not intended to be
  201.  * used outside it. Please do not make use of this header, except
  202.  * if you're a KDEPrint developer. The API might change in the
  203.  * future and binary compatibility might be broken.
  204.  */
  205. class KDEPRINT_EXPORT DrStringOption : public DrBase
  206. {
  207. public:
  208.     DrStringOption();
  209.     ~DrStringOption();
  210.  
  211.     virtual QString valueText();
  212.     virtual void setValueText(const QString& s);
  213.  
  214. protected:
  215.     QString    m_value;
  216. };
  217.  
  218. /**********************************
  219.  * Integer numerical option class *
  220.  **********************************/
  221.  
  222. /**
  223.  * @internal
  224.  * This class is internal to KDEPrint and is not intended to be
  225.  * used outside it. Please do not make use of this header, except
  226.  * if you're a KDEPrint developer. The API might change in the
  227.  * future and binary compatibility might be broken.
  228.  */
  229. class KDEPRINT_EXPORT DrIntegerOption : public DrBase
  230. {
  231. public:
  232.     DrIntegerOption();
  233.     ~DrIntegerOption();
  234.  
  235.     virtual QString valueText();
  236.     virtual void setValueText(const QString& s);
  237.     QString fixedVal();
  238.  
  239. protected:
  240.     int    m_value;
  241. };
  242.  
  243. /********************************
  244.  * Float numerical option class *
  245.  ********************************/
  246.  
  247. /**
  248.  * @internal
  249.  * This class is internal to KDEPrint and is not intended to be
  250.  * used outside it. Please do not make use of this header, except
  251.  * if you're a KDEPrint developer. The API might change in the
  252.  * future and binary compatibility might be broken.
  253.  */
  254. class KDEPRINT_EXPORT DrFloatOption : public DrBase
  255. {
  256. public:
  257.     DrFloatOption();
  258.     ~DrFloatOption();
  259.  
  260.     virtual QString valueText();
  261.     virtual void setValueText(const QString& s);
  262.     QString fixedVal();
  263.  
  264. protected:
  265.     float    m_value;
  266. };
  267.  
  268. /***********************
  269.  * Single choice class *
  270.  ***********************/
  271.  
  272. /**
  273.  * @internal
  274.  * This class is internal to KDEPrint and is not intended to be
  275.  * used outside it. Please do not make use of this header, except
  276.  * if you're a KDEPrint developer. The API might change in the
  277.  * future and binary compatibility might be broken.
  278.  */
  279. class KDEPRINT_EXPORT DrListOption : public DrBase
  280. {
  281. public:
  282.     DrListOption();
  283.     ~DrListOption();
  284.  
  285.     void addChoice(DrBase *ch)    { m_choices.append(ch); }
  286.     QPtrList<DrBase>* choices()    { return &m_choices; }
  287.     DrBase* currentChoice() const     { return m_current; }
  288.     DrBase* findChoice(const QString& txt);
  289.     void setChoice(int choicenum);
  290.  
  291.     virtual QString valueText();
  292.     virtual QString prettyText();
  293.     virtual void setValueText(const QString& s);
  294.     void setOptions(const QMap<QString,QString>& opts);
  295.     void getOptions(QMap<QString,QString>& opts, bool incldef = false);
  296.     DriverItem* createItem(DriverItem *parent, DriverItem *after = 0);
  297.     DrBase* clone();
  298.  
  299. protected:
  300.     QPtrList<DrBase>    m_choices;
  301.     DrBase        *m_current;
  302. };
  303.  
  304. /**
  305.  * @internal
  306.  * This class is internal to KDEPrint and is not intended to be
  307.  * used outside it. Please do not make use of this header, except
  308.  * if you're a KDEPrint developer. The API might change in the
  309.  * future and binary compatibility might be broken.
  310.  */
  311. class KDEPRINT_EXPORT DrBooleanOption : public DrListOption
  312. {
  313.     /* just an overloaded class, with different type */
  314. public:
  315.     DrBooleanOption() : DrListOption() { m_type = DrBase::Boolean; }
  316.     ~DrBooleanOption() {}
  317. };
  318.  
  319. /********************
  320.  * Constraint class *
  321.  ********************/
  322.  
  323. /**
  324.  * @internal
  325.  * This class is internal to KDEPrint and is not intended to be
  326.  * used outside it. Please do not make use of this header, except
  327.  * if you're a KDEPrint developer. The API might change in the
  328.  * future and binary compatibility might be broken.
  329.  */
  330. class DrConstraint
  331. {
  332. public:
  333.     DrConstraint(const QString& o1, const QString& o2, const QString& c1 = QString::null, const QString& c2 = QString::null);
  334.     DrConstraint(const DrConstraint&);
  335.  
  336.     bool check(DrMain*);
  337.  
  338. protected:
  339.     QString        m_opt1, m_opt2;
  340.     QString        m_choice1, m_choice2;
  341.     DrListOption    *m_option1, *m_option2;
  342. };
  343.  
  344. /*******************
  345.  * Page Size class *
  346.  *******************/
  347.  
  348. /**
  349.  * @internal
  350.  * This class is internal to KDEPrint and is not intended to be
  351.  * used outside it. Please do not make use of this header, except
  352.  * if you're a KDEPrint developer. The API might change in the
  353.  * future and binary compatibility might be broken.
  354.  */
  355. class DrPageSize
  356. {
  357. public:
  358.     DrPageSize(const QString& s, float width, float height, float left, float bottom, float right, float top);
  359.     DrPageSize(const DrPageSize&);
  360.  
  361.     /**
  362.      * All dimensions are int dot: 1/72th of an inch ( PostScript ).
  363.      * When rounded, the rounding is made safely: upward for a margin,
  364.      * downward for a page size.
  365.      */
  366.     float pageWidth() const    { return m_width; }
  367.     float pageHeight() const   { return m_height; }
  368.     float leftMargin() const   { return m_left; }
  369.     float rightMargin() const  { return m_right; }
  370.     float topMargin() const    { return m_top; }
  371.     float bottomMargin() const { return m_bottom; }
  372.     QString pageName() const   { return m_name; }
  373.  
  374.     QSize pageSize() const;
  375.     QRect pageRect() const;
  376.     QSize margins() const;
  377.  
  378. protected:
  379.     QString    m_name;
  380.     float m_width, m_height, m_left, m_bottom, m_right, m_top;
  381. };
  382.  
  383. #endif
  384.